package MapandSetHomeWork;

import java.util.Comparator;
import java.util.TreeMap;
class Student {
    public String name;

    public int age;

    public Student() {

    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

}

class StudentComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        if(o1.name.equals(o2.name)) {
            return o1.age - o2.age;
        } else {
            return o1.name.compareTo(o2.name);
        }
    }
}
public class BugOnceMore {
    public static void main(String[] args) {
        TreeMap<Student,Integer> map = new TreeMap(new StudentComparator());
        map.put(new Student("djm",22),1);
        map.put(new Student("zzx",24),2);

        System.out.println(map);
    }
}
